﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Globalization;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for AuctionRegistrationManagerTest and is intended
    ///to contain all AuctionRegistrationManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AuctionRegistrationManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for RegisterAuction
        ///</summary>
        [TestMethod()]
        public void RegisterAuctionTestSuccessful()
        {

            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "passwd123", "passwd123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Nokia", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Bolivianos", user.Id, "1");
            string initialAmount = "50"; // TODO: Initialize to an appropriate value
            string currency = "Dollars"; // TODO: Initialize to an appropriate value
            string productId = product.ProductId.ToString(CultureInfo.CurrentCulture); // TODO: Initialize to an appropriate value
            DateTime date = DateTime.Now.AddDays(5);
            int hour = 14; // TODO: Initialize to an appropriate value
            int minutes = 30; // TODO: Initialize to an appropriate value
            Auction actual;
            actual = AuctionRegistrationManager.RegisterAuction(email, initialAmount, currency, productId, date, hour, minutes);
            Assert.AreNotEqual(null, actual);
            Assert.AreEqual(Convert.ToInt64(initialAmount), actual.LastBidPrice);
            Assert.AreEqual(currency, actual.Currency);
            Assert.AreEqual(Convert.ToInt64(productId), actual.ProductId);
        }

        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void RegisterAuctionInvalidAmount()
        {
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "passwd123", "passwd123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; 
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Nokia2", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id,"1");
            string initialAmount = "aagfghgf"; // TODO: Initialize to an appropriate value
            string currency = "Dollars"; // TODO: Initialize to an appropriate value
            string productId = product.ProductId.ToString(CultureInfo.CurrentCulture); // TODO: Initialize to an appropriate value
            DateTime date = Convert.ToDateTime("04/05/2012 00:00:00"); // TODO: Initialize to an appropriate value
            int hour = 14; // TODO: Initialize to an appropriate value
            int minutes = 30; // TODO: Initialize to an appropriate value
            Auction actual;
            actual = AuctionRegistrationManager.RegisterAuction(email, initialAmount, currency, productId, date, hour, minutes);
        }

        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void RegisterAuctionBlankItems()
        {
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "passwd123", "passwd123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Nokia3", "300", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            string initialAmount = ""; // TODO: Initialize to an appropriate value
            string currency = ""; // TODO: Initialize to an appropriate value
            string productId = product.ProductId.ToString(CultureInfo.CurrentCulture); // TODO: Initialize to an appropriate value
            DateTime date = Convert.ToDateTime("04/05/2012 00:00:00"); // TODO: Initialize to an appropriate value
            int hour = 14; // TODO: Initialize to an appropriate value
            int minutes = 30; // TODO: Initialize to an appropriate value
            Auction actual;
            actual = AuctionRegistrationManager.RegisterAuction(email, initialAmount, currency, productId, date, hour, minutes);
        }

        
    }
}
